home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / tex / PasTeX14-BETA-6 / SpecialHost / Source / Host.c < prev    next >
C/C++ Source or Header  |  1994-07-25  |  50KB  |  2,399 lines

  1. /*
  2. **    SpecialHost for PasTeX
  3. **
  4. **    Copyright © by Olaf Barthel & Georg Heßmann
  5. */
  6.  
  7. #include "Global.h"
  8.  
  9. #include "SpecialHost_rev.h"
  10.  
  11. #define TEMPLATE    "TRANSFER/K,RENDER/K,BASEDEPI/K/N,INVERT/S,USESCREEN/S,NOGUI/S"
  12.  
  13. enum    {    ARG_TRANSFER,ARG_RENDER,ARG_BASEDPI,ARG_INVERT,ARG_USESCREEN,ARG_NOGUI,
  14.         ARGCOUNT
  15.     };
  16.  
  17. STATIC VOID __saveds ChildFunc(VOID);
  18.  
  19. LONG __saveds
  20. Main(VOID)
  21. {
  22.     LONG             Result = RETURN_FAIL;
  23.     BOOL             NeedStack;
  24.     struct WBStartup    *WBenchMsg;
  25.  
  26.     SysBase = *(struct ExecBase **)4;
  27.  
  28.     Father = (struct Process *)SysBase -> ThisTask;
  29.  
  30.     if(Father -> pr_CLI)
  31.     {
  32.         NeedStack = (((struct CommandLineInterface *)BADDR(Father -> pr_CLI)) -> cli_DefaultStack < 8192);
  33.  
  34.         WBenchMsg = NULL;
  35.     }
  36.     else
  37.     {
  38.         WaitPort(&Father -> pr_MsgPort);
  39.  
  40.         WBenchMsg = (struct WBStartup *)GetMsg(&Father -> pr_MsgPort);
  41.  
  42.         NeedStack = ((LONG)SysBase -> ThisTask -> tc_SPUpper - (LONG)SysBase -> ThisTask -> tc_SPLower < 32768);
  43.     }
  44.  
  45.     if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37))
  46.     {
  47.         if(UtilityBase = OpenLibrary("utility.library",37))
  48.         {
  49.             BPTR    OldDir,
  50.                 Stream        = NULL,
  51.                 OldCOS        = NULL;
  52.             APTR    OldConsoleTask    = NULL;
  53.  
  54.             if(WBenchMsg)
  55.                 OldDir = CurrentDir(WBenchMsg -> sm_ArgList[0] . wa_Lock);
  56.  
  57.             ReadConfig(&Configuration);
  58.  
  59.             if(Father -> pr_CLI)
  60.             {
  61.                 struct RDArgs    *ArgsPtr;
  62.                 STRPTR         Arg[ARGCOUNT];
  63.                 LONG         TransferMode    = CYID_Transfer_Memory,
  64.                          RenderMode    = CYID_Render_None,
  65.                          ID;
  66.  
  67.                 memset(Arg,0,sizeof(Arg));
  68.  
  69.                 if(ArgsPtr = ReadArgs(TEMPLATE,(LONG *)Arg,NULL))
  70.                 {
  71.                     if(Arg[ARG_TRANSFER])
  72.                     {
  73.                         if((ID = GetMapCode(TransferTable,Arg[ARG_TRANSFER])) != -1)
  74.                             TransferMode = ID;
  75.                     }
  76.  
  77.                     if(Arg[ARG_RENDER])
  78.                     {
  79.                         if((ID = GetMapCode(RenderTable,Arg[ARG_RENDER])) != -1)
  80.                             RenderMode = ID;
  81.                     }
  82.  
  83.                     if(Arg[ARG_BASEDPI])
  84.                     {
  85.                         if((ID = *(LONG *)Arg[ARG_BASEDPI]) > 0)
  86.                             Configuration . base_dpi = ID;
  87.                     }
  88.  
  89.                     if(Arg[ARG_INVERT])
  90.                         Configuration . invert_bmap = TRUE;
  91.  
  92.                     if(Arg[ARG_USESCREEN])
  93.                         Configuration . use_pubscr = TRUE;
  94.  
  95.                     if(Arg[ARG_NOGUI])
  96.                         UseGUI = FALSE;
  97.  
  98.                     ChangeDrawMode(TransferMode,RenderMode,FALSE);
  99.  
  100.                     FreeArgs(ArgsPtr);
  101.                 }
  102.             }
  103.             else
  104.             {
  105.                 if(IconBase = OpenLibrary("icon.library",37))
  106.                 {
  107.                     struct DiskObject *Icon;
  108.  
  109.                     if(Icon = GetDiskObject(WBenchMsg -> sm_ArgList[0] . wa_Name))
  110.                     {
  111.                         STRPTR    Data;
  112.                         LONG    TransferMode    = CYID_Transfer_Memory,
  113.                             RenderMode    = CYID_Render_None,
  114.                             ID;
  115.  
  116.                         if(Data = FindToolType(Icon -> do_ToolTypes,"TRANSFER"))
  117.                         {
  118.                             if((ID = GetMapCode(TransferTable,Data)) != -1)
  119.                                 TransferMode = ID;
  120.                         }
  121.  
  122.                         if(Data = FindToolType(Icon -> do_ToolTypes,"RENDER"))
  123.                         {
  124.                             if((ID = GetMapCode(RenderTable,Data)) != -1)
  125.                                 RenderMode = ID;
  126.                         }
  127.  
  128.                         if(Data = FindToolType(Icon -> do_ToolTypes,"BASEDPI"))
  129.                         {
  130.                             if(StrToLong(Data,&ID) > 0)
  131.                             {
  132.                                 if(ID > 0)
  133.                                     Configuration . base_dpi = ID;
  134.                             }
  135.                         }
  136.  
  137.                         if(FindToolType(Icon -> do_ToolTypes,"INVERT"))
  138.                             Configuration . invert_bmap = TRUE;
  139.  
  140.                         if(FindToolType(Icon -> do_ToolTypes,"USESCREEN"))
  141.                             Configuration . use_pubscr = TRUE;
  142.  
  143.                         if(FindToolType(Icon -> do_ToolTypes,"NOGUI"))
  144.                             UseGUI = FALSE;
  145.  
  146.                         ChangeDrawMode(TransferMode,RenderMode,FALSE);
  147.  
  148.                         FreeDiskObject(Icon);
  149.                     }
  150.  
  151.                     CloseLibrary(IconBase);
  152.                 }
  153.  
  154.                 if(!UseGUI)
  155.                 {
  156.                     if(Configuration . use_pubscr)
  157.                         Stream = Open("CON:20/20/400/80/SpecialHost/SCREENShowDVI-PubScr",MODE_NEWFILE);
  158.                     else
  159.                         Stream = Open("CON:20/20/400/80/SpecialHost",MODE_NEWFILE);
  160.  
  161.                     if(Stream)
  162.                     {
  163.                         struct FileHandle *Handle = (struct FileHandle *)BADDR(Stream);
  164.  
  165.                         OldConsoleTask = Father -> pr_ConsoleTask;
  166.  
  167.                         Father -> pr_ConsoleTask = (APTR)Handle -> fh_Type;
  168.  
  169.                         OldCOS = Father -> pr_COS;
  170.  
  171.                         if(!(Father -> pr_COS = Open("*",MODE_NEWFILE)))
  172.                         {
  173.                             Father -> pr_COS        = OldCOS;
  174.                             Father -> pr_ConsoleTask    = OldConsoleTask;
  175.  
  176.                             Close(Stream);
  177.  
  178.                             Stream = NULL;
  179.  
  180.                             UseGUI = TRUE;
  181.                         }
  182.                     }
  183.                     else
  184.                         UseGUI = TRUE;
  185.                 }
  186.             }
  187.  
  188.             if(NeedStack)
  189.             {
  190.                 Forbid();
  191.  
  192.                 SetSignal(0,SIGF_SINGLE);
  193.  
  194.                 if(CreateNewProcTags(
  195.                     NP_CommandName,    "SpecialHost Child",
  196.                     NP_Name,    "SpecialHost Child Process",
  197.                     NP_Output,    Father -> pr_COS,
  198.                     NP_CloseOutput,    FALSE,
  199.                     NP_StackSize,    32768,
  200.                     NP_Entry,    ChildFunc,
  201.                     NP_Cli,        (WBenchMsg == NULL),
  202.                 TAG_DONE))
  203.                 {
  204.                     ULONG Signals;
  205.  
  206.                     Result = RETURN_OK;
  207.  
  208.                     Wait(SIGF_SINGLE);
  209.  
  210.                     while(1)
  211.                     {
  212.                         Signals = Wait(SIGF_SINGLE | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  213.  
  214.                         if(Signals & SIGF_SINGLE)
  215.                             break;
  216.                         else
  217.                             Signal(ThisProcess,Signals);
  218.                     }
  219.                 }
  220.  
  221.                 Permit();
  222.             }
  223.             else
  224.             {
  225.                 HandleInput();
  226.  
  227.                 Result = RETURN_OK;
  228.             }
  229.  
  230.             if(Stream)
  231.             {
  232.                 BPTR NewCOS = Father -> pr_COS;
  233.  
  234.                 Father -> pr_COS        = OldCOS;
  235.                 Father -> pr_ConsoleTask    = OldConsoleTask;
  236.  
  237.                 Close(Stream);
  238.                 Close(NewCOS);
  239.             }
  240.  
  241.             if(WBenchMsg)
  242.                 CurrentDir(OldDir);
  243.  
  244.             CloseLibrary(UtilityBase);
  245.         }
  246.  
  247.         CloseLibrary(DOSBase);
  248.     }
  249.  
  250.     if(WBenchMsg)
  251.     {
  252.         Forbid();
  253.  
  254.         ReplyMsg(&WBenchMsg -> sm_Message);
  255.     }
  256.     else
  257.         return(Result);
  258. }
  259.  
  260. int _FPERR;
  261. void _CXFERR(int code) {}
  262.  
  263. STATIC VOID __saveds
  264. ChildFunc()
  265. {
  266.     Signal(Father,SIGF_SINGLE);
  267.  
  268.     HandleInput();
  269.  
  270.     Forbid();
  271.  
  272.     Signal(Father,SIGF_SINGLE);
  273. }
  274.  
  275. BOOL __regargs
  276. BuildName(STRPTR LocalBuffer,BPTR Home,STRPTR Source,LONG ResX,LONG ResY,ULONG CRC,LONG *Error)
  277. {
  278.     UBYTE    NewDir[40];
  279.     STRPTR    Index;
  280.     BOOL    Success = FALSE;
  281.  
  282.     *Error = 0;
  283.  
  284.     strcpy(LocalBuffer,Source);
  285.  
  286.     if(FilePart(LocalBuffer) == LocalBuffer)
  287.     {
  288.         if(Home == (BPTR)~0)
  289.             LocalBuffer[0] = 0;
  290.         else
  291.         {
  292.             if(!NameFromLock(Home,LocalBuffer,MAX_FILENAME_LEN))
  293.             {
  294.                 *Error = IoErr();
  295.  
  296.                 return(FALSE);
  297.             }
  298.         }
  299.     }
  300.     else
  301.     {
  302.         Index = PathPart(LocalBuffer);
  303.  
  304.         *Index = 0;
  305.     }
  306.  
  307.     sprintf(NewDir,"SpecialHost_%dx%d",ResX,ResY);
  308.  
  309.     if(AddPart(LocalBuffer,NewDir,MAX_FILENAME_LEN))
  310.     {
  311.         BPTR FileLock;
  312.  
  313.         if(FileLock = Lock(LocalBuffer,ACCESS_READ))
  314.         {
  315.             struct FileInfoBlock *FileInfo;
  316.  
  317.             if(FileInfo = (struct FileInfoBlock *)AllocDosObjectTags(DOS_FIB,TAG_DONE))
  318.             {
  319.                 if(Examine(FileLock,FileInfo))
  320.                 {
  321.                     if(FileInfo -> fib_DirEntryType > 0)
  322.                         Success = TRUE;
  323.                     else
  324.                         *Error = ERROR_OBJECT_WRONG_TYPE;
  325.                 }
  326.                 else
  327.                     *Error = IoErr();
  328.  
  329.                 FreeDosObject(DOS_FIB,FileInfo);
  330.             }
  331.             else
  332.                 *Error = IoErr();
  333.         }
  334.         else
  335.         {
  336.             LONG LocalError = IoErr();
  337.  
  338.             if(LocalError == ERROR_OBJECT_NOT_FOUND)
  339.             {
  340.                 if(FileLock = CreateDir(LocalBuffer))
  341.                 {
  342.                     Success = TRUE;
  343.  
  344.                     UnLock(FileLock);
  345.                 }
  346.                 else
  347.                     *Error = IoErr();
  348.             }
  349.             else
  350.                 *Error = LocalError;
  351.         }
  352.     }
  353.     else
  354.         *Error = IoErr();
  355.  
  356.     if(Success)
  357.     {
  358.         UBYTE Source2[32];
  359.  
  360.         sprintf(Source2,"%.20s_%1s%08lx",FilePart(Source),(Configuration . invert_bmap ? "I" : "N"), CRC);
  361.         
  362.         if(!AddPart(LocalBuffer,Source2,MAX_FILENAME_LEN))
  363.         {
  364.             *Error = IoErr();
  365.  
  366.             Success = FALSE;
  367.         }
  368.     }
  369.  
  370.     return(Success);
  371. }
  372.  
  373. VOID __regargs
  374. SetSleep(BOOL Mode)
  375. {
  376.     if(AP_Application)
  377.     {
  378.         if(Mode)
  379.         {
  380.             struct Window *Window;
  381.  
  382.             Forbid();
  383.  
  384.             if(get(WI_Main,MUIA_Window_Window,&Window))
  385.                 ThisProcess -> pr_WindowPtr = Window;
  386.  
  387.             Permit();
  388.  
  389.             set(AP_Application,MUIA_Application_Sleep,TRUE);
  390.         }
  391.         else
  392.         {
  393.             ThisProcess -> pr_WindowPtr = OldPtr;
  394.  
  395.             set(AP_Application,MUIA_Application_Sleep,FALSE);
  396.         }
  397.     }
  398. }
  399.  
  400. BPTR __regargs
  401. OpenConfigFile(STRPTR Name,LONG Mode)
  402. {
  403.     UBYTE    Env[MAX_FILENAME_LEN],
  404.         Path[MAX_FILENAME_LEN];
  405.     STRPTR    Index;
  406.     LONG    Len;
  407.     BPTR    File;
  408.  
  409.     if(GetVar("TEXCONFIG",Env,MAX_FILENAME_LEN,NULL) < 1)
  410.         strcpy(Env,"TeX:config");
  411.  
  412.     Index = strtok(Env,",;");
  413.  
  414.     do
  415.     {
  416.         strcpy(Path,Index);
  417.  
  418.         Len = strlen(Path);
  419.  
  420.         if(Path[Len - 1] != ':' && Path[Len - 1] != '/')
  421.         {
  422.             Path[Len]    = '/';
  423.             Path[Len + 1]    = 0;
  424.         }
  425.  
  426.         if(!strcmp(Path,"./"))
  427.             Path[0] = 0;
  428.  
  429.         strcat(Path,Name);
  430.  
  431.         if(File = Open(Path,Mode))
  432.             return(File);
  433.     }
  434.     while(Index = strtok(NULL,",;"));
  435.  
  436.     return(NULL);
  437. }
  438.  
  439. BOOL __regargs
  440. ReadConfig(struct config_struct *ConfigPtr)
  441. {
  442.     BPTR File;
  443.     BOOL Result = FALSE;
  444.  
  445.     if(File = OpenConfigFile("SpecialHost.config",MODE_OLDFILE))
  446.     {
  447.         struct config_struct Config;
  448.  
  449.         if(Read(File,&Config,sizeof(struct config_struct)) == sizeof(struct config_struct))
  450.         {
  451.             if(Config . magic == CONFIG_FILE_MAGIC && Config . version <= CONFIG_FILE_VERSION)
  452.             {
  453.                 if(Config . use_pubscr != ConfigPtr -> use_pubscr)
  454.                     Result = TRUE;
  455.  
  456.                 CopyMem(&Config,ConfigPtr,sizeof(struct config_struct));
  457.             }
  458.             else
  459.                 PrintLine("\33bConfiguration file format is too old.\33n");
  460.         }
  461.         else
  462.             PrintLine("\33bError reading configuration file.\33n");
  463.  
  464.         Close(File);
  465.     }
  466.     else
  467.         PrintLine("\33bFailed to open configuration file.\33n");
  468.  
  469.     return(Result);
  470. }
  471.  
  472. VOID __regargs
  473. SaveConfig(struct config_struct *ConfigPtr)
  474. {
  475.     BPTR File;
  476.  
  477.     if(File = OpenConfigFile("SpecialHost.config",MODE_NEWFILE))
  478.     {
  479.         if(Write(File,ConfigPtr,sizeof(struct config_struct)) != sizeof(struct config_struct))
  480.             PrintLine("\33bError writing configuration file.\33n");
  481.  
  482.         Close(File);
  483.     }
  484.     else
  485.         PrintLine("\33bFailed to open configuration file.\33n");
  486. }
  487.  
  488. VOID
  489. ChangeDrawMode(LONG Transfer,LONG Render,BOOL GetThem)
  490. {
  491.     if(GetThem)
  492.     {
  493.         if(!CY_Transfer || !CY_Render)
  494.             return;
  495.         else
  496.         {
  497.             get(CY_Transfer,MUIA_Cycle_Active,&Transfer);
  498.             get(CY_Render,    MUIA_Cycle_Active,&Render);
  499.         }
  500.     }
  501.  
  502.     switch(Transfer)
  503.     {
  504.         case CYID_Transfer_Memory:
  505.  
  506.             switch(Render)
  507.             {
  508.                 case CYID_Render_None:
  509.  
  510.                     Configuration . draw_modus = DRAW_IN_MEM;
  511.                     break;
  512.  
  513.                 case CYID_Render_Frame:
  514.  
  515.                     Configuration . draw_modus = DRAW_IN_MEM_B;
  516.                     break;
  517.  
  518.                 case CYID_Render_Clear:
  519.  
  520.                     Configuration . draw_modus = DRAW_RECT;
  521.                     break;
  522.             }
  523.  
  524.             break;
  525.  
  526.         case CYID_Transfer_Disk:
  527.  
  528.             switch(Render)
  529.             {
  530.                 case CYID_Render_None:
  531.  
  532.                     Configuration . draw_modus = DRAW_FILE;
  533.                     break;
  534.  
  535.                 case CYID_Render_Frame:
  536.  
  537.                     Configuration . draw_modus = DRAW_FILE_B;
  538.                     break;
  539.  
  540.                 case CYID_Render_Clear:
  541.  
  542.                     Configuration . draw_modus = DRAW_BORDER;
  543.                     break;
  544.             }
  545.  
  546.             break;
  547.  
  548.         case CYID_Transfer_None:
  549.  
  550.             switch(Render)
  551.             {
  552.                 case CYID_Render_None:
  553.  
  554.                     Configuration . draw_modus = DRAW_RECT;
  555.                     break;
  556.  
  557.                 case CYID_Render_Frame:
  558.  
  559.                     Configuration . draw_modus = DRAW_BORDER;
  560.                     break;
  561.  
  562.                 case CYID_Render_Clear:
  563.  
  564.                     Configuration . draw_modus = DRAW_RECT;
  565.                     break;
  566.             }
  567.  
  568.             break;
  569.     }
  570. }
  571.  
  572. VOID __inline
  573. LibraryCleanup(struct Library **Library)
  574. {
  575.     if(*Library)
  576.     {
  577.         CloseLibrary(*Library);
  578.  
  579.         *Library = NULL;
  580.     }
  581. }
  582.  
  583. BOOL
  584. OpenGUI()
  585. {
  586.     STRPTR Version = VERSTAG;
  587.  
  588.     AP_Application = ApplicationObject,
  589.         MUIA_Application_Title,        "SpecialHost",
  590.         MUIA_Application_Version,    Version + 1,
  591.         MUIA_Application_Copyright,    "Copyright © 1993-1994 by Olaf `Olsen' Barthel & Georg Heßmann",
  592.         MUIA_Application_Author,    "Olaf `Olsen' Barthel & Georg Heßmann",
  593.         MUIA_Application_Description,    "PasTeX special extension processor",
  594.         MUIA_Application_Base,        "SPECIALHOST",
  595.         MUIA_Application_Menu,        MenuTemplate,
  596.  
  597.         SubWindow,
  598.             WI_Main = WindowObject,
  599.                 MUIA_Window_Title,    "SpecialHost",
  600.                 MUIA_Window_ID,        MAKE_ID('M','A','I','N'),
  601.                 WindowContents,        VGroup,
  602.  
  603.                     Child,    HGroup,
  604.                         Child,    ColGroup(2),GroupFrameT("Image"),
  605.                             Child,    KeyLabel1("Transfer",'t'),    Child,    CY_Transfer    = KeyCycle(CYA_Transfer,'t'),
  606.                             Child,    KeyLabel1("Rendering",'r'),    Child,    CY_Render    = KeyCycle(CYA_Render,'r'),
  607.                             Child,    KeyLabel1("Invert",'i'),    Child,    HGroup,
  608.                                                     Child,    CM_Invert    = KeyCheckMark(FALSE,'i'),
  609.                                                     Child,    HSpace(FALSE),
  610.                                                     End,
  611.                             Child,    KeyLabel2("Base DPI",'b'),    Child,    ST_BaseDPI = StringObject,
  612.                                                             StringFrame,
  613.                                                             MUIA_String_Integer,    100,
  614.                                                             MUIA_String_Accept,    "1234567890",
  615.                                                             MUIA_String_MaxLen,    5,
  616.                                                             MUIA_ControlChar,    'b',
  617.                                                     End,
  618.                             End,
  619.                         End,
  620.  
  621.                     Child,    HGroup,
  622.                         GroupFrameT("Messages"),
  623.                         Child,    LV_Messages = ListviewObject,
  624.                             MUIA_Listview_Input,    FALSE,
  625.                             MUIA_Listview_List,    ListObject,
  626.                                             ReadListFrame,
  627.                                         End,
  628.                             End,
  629.                         End,
  630.  
  631.                     Child,    VGroup,GroupFrame,
  632.                         Child,    GA_Gauge = GaugeObject,
  633.                             GaugeFrame,
  634.                             MUIA_Gauge_Horiz,    TRUE,
  635.                             MUIA_Weight,        0,
  636.                             End,
  637.                         Child,    RectangleObject,
  638.                             MUIA_Weight,        0,
  639.                             End,
  640.                         Child,    ScaleObject,
  641.                             End,
  642.                         End,
  643.                     Child,    HGroup,
  644.                         MUIA_Group_SameSize, TRUE,
  645.                         Child,    BT_Jump        = KeyButton("Jump to ShowDVI",'j'),
  646.                         Child,    BT_Show        = KeyButton("ShowDVI to front",'f'),
  647.                         Child,    BT_Clear    = KeyButton("Clear",'c'),
  648.                         End,
  649.                 End,
  650.             End,
  651.     End;
  652.  
  653.     if(AP_Application)
  654.     {
  655.         struct ListEntry    *Entry = (struct ListEntry *)MessageList . lh_Head;
  656.         struct Window        *Window;
  657.  
  658.         DoMethod(WI_Main,    MUIM_Notify,MUIA_Window_CloseRequest,    TRUE,        AP_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  659.         DoMethod(CY_Transfer,    MUIM_Notify,MUIA_Cycle_Active,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_TRANSFER);
  660.         DoMethod(CY_Render,    MUIM_Notify,MUIA_Cycle_Active,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_RENDER);
  661.         DoMethod(CM_Invert,    MUIM_Notify,MUIA_Selected,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_INVERT);
  662.         DoMethod(ST_BaseDPI,    MUIM_Notify,MUIA_String_Contents,    MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_BASEDPI);
  663.         DoMethod(BT_Jump,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_JUMP);
  664.         DoMethod(BT_Show,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_SHOW);
  665.         DoMethod(BT_Clear,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_CLEAR);
  666.  
  667.         DoMethod(WI_Main,    MUIM_Window_SetCycleChain,CY_Transfer,CY_Render,CM_Invert,ST_BaseDPI,LV_Messages,BT_Jump,BT_Show,BT_Clear,NULL);
  668.  
  669.         while(Entry -> MinNode . mln_Succ)
  670.         {
  671.             DoMethod(LV_Messages,MUIM_List_Insert,&Entry -> Title,1,MUIV_List_Insert_Bottom);
  672.  
  673.             Entry = (struct ListEntry *)Entry -> MinNode . mln_Succ;
  674.         }
  675.  
  676.         set(LV_Messages,MUIA_List_Active,MUIV_List_Active_Bottom);
  677.  
  678.         switch(Configuration . draw_modus)
  679.         {
  680.             case DRAW_IN_MEM:
  681.  
  682.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  683.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  684.                 break;
  685.  
  686.             case DRAW_FILE:
  687.  
  688.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  689.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  690.                 break;
  691.  
  692.             case DRAW_IN_MEM_B:
  693.  
  694.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  695.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  696.                 break;
  697.  
  698.             case DRAW_FILE_B:
  699.  
  700.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  701.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  702.                 break;
  703.  
  704.             case DRAW_BORDER:
  705.  
  706.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  707.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  708.                 break;
  709.  
  710.             case DRAW_RECT:
  711.  
  712.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  713.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Clear);
  714.                 break;
  715.         }
  716.  
  717.         set(CM_Invert,MUIA_Selected,Configuration . invert_bmap);
  718.  
  719.         InvertChanged = TRUE;
  720.  
  721.         set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  722.  
  723.         if(PubScreen)
  724.         {
  725.             UnlockPubScreen(NULL,PubScreen);
  726.  
  727.             PubScreen = NULL;
  728.         }
  729.  
  730.         if(Configuration . use_pubscr)
  731.         {
  732.             if(PubScreen = LockPubScreen("ShowDVI-PubScr"))
  733.             {
  734.                 set(WI_Main,MUIA_Window_Screen,PubScreen);
  735.  
  736.                 set(BT_Jump,MUIA_Disabled,TRUE);
  737.             }
  738.             else
  739.                 Configuration . use_pubscr = FALSE;
  740.         }
  741.  
  742.         set(WI_Main,MUIA_Window_Open,TRUE);
  743.  
  744.         Forbid();
  745.  
  746.         if(get(WI_Main,MUIA_Window_Window,&Window))
  747.         {
  748.             if(Window)
  749.             {
  750.                 struct MenuItem *Item;
  751.  
  752.                 if(Item = ItemAddress(Window -> MenuStrip,FULLMENUNUM(0,3,NOSUB)))
  753.                 {
  754.                     if(Configuration . use_pubscr)
  755.                         Item -> Flags |= CHECKED;
  756.                     else
  757.                         Item -> Flags &= ~CHECKED;
  758.                 }
  759.  
  760.                 Permit();
  761.  
  762.                 return(TRUE);
  763.             }
  764.         }
  765.  
  766.         Permit();
  767.  
  768.         if(PubScreen)
  769.         {
  770.             UnlockPubScreen(NULL,PubScreen);
  771.  
  772.             PubScreen = NULL;
  773.         }
  774.  
  775.         DisposeObject(AP_Application);
  776.  
  777.         AP_Application = NULL;
  778.     }
  779.  
  780.     return(FALSE);
  781. }
  782.  
  783. VOID
  784. CloseAll()
  785. {
  786.     if(ThisProcess)
  787.         ThisProcess -> pr_WindowPtr = OldPtr;
  788.  
  789.     if(MainPort)
  790.     {
  791.         struct special_msg *Message;
  792.  
  793.         RemPort(MainPort);
  794.  
  795.         while(Message = (struct special_msg *)GetMsg(MainPort))
  796.         {
  797.             Message -> action    = AC_REPLY_UNKNOWN;
  798.             Message -> ret        = 0;
  799.  
  800.             ReplyMsg((struct Message *)Message);
  801.         }
  802.  
  803.         DeleteMsgPort(MainPort);
  804.     }
  805.  
  806.     if(Pool)
  807.         LibDeletePool(Pool);
  808.  
  809.     LibraryCleanup(&MUIMasterBase);
  810.     LibraryCleanup(&DataTypesBase);
  811. /*
  812.     LibraryCleanup(&MathBase);
  813.     LibraryCleanup(&MathTransBase);
  814. */
  815.     LibraryCleanup(&MathIeeeDoubBasBase);
  816.     LibraryCleanup(&MathIeeeDoubTransBase);
  817.  
  818.     LibraryCleanup(&AslBase);
  819.     LibraryCleanup(&IFFParseBase);
  820.     LibraryCleanup(&GadToolsBase);
  821.     LibraryCleanup(&GfxBase);
  822.     LibraryCleanup(&IntuitionBase);
  823. }
  824.  
  825. BOOL
  826. OpenAll()
  827. {
  828.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  829.  
  830.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
  831.     {
  832.         ShowError(ERR_NO_INTUITION,NULL,FALSE);
  833.  
  834.         return(FALSE);
  835.     }
  836.  
  837.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
  838.     {
  839.         ShowError(ERR_NO_GRAPHICS,NULL,FALSE);
  840.  
  841.         return(FALSE);
  842.     }
  843.  
  844.     if(!(GadToolsBase = OpenLibrary("gadtools.library",37)))
  845.     {
  846.         ShowError(ERR_NO_GADTOOLS,NULL,FALSE);
  847.  
  848.         return(FALSE);
  849.     }
  850.  
  851.     if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
  852.     {
  853.         ShowError(ERR_NO_IFFPARSE,NULL,FALSE);
  854.  
  855.         return(FALSE);
  856.     }
  857.  
  858.     if(!(AslBase = OpenLibrary("asl.library",37)))
  859.     {
  860.         ShowError(ERR_NO_ASL,NULL,FALSE);
  861.  
  862.         return(FALSE);
  863.     }
  864.  
  865. /*    if(!(MathBase = OpenLibrary("mathffp.library",0)))*/
  866.  
  867.     if(!(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",0)))
  868.     {
  869.         ShowError(ERR_NO_MATHFFP,NULL,FALSE);
  870.  
  871.         return(FALSE);
  872.     }
  873.  
  874. /*    if(!(MathTransBase = OpenLibrary("mathtrans.library",0)))*/
  875.  
  876.     if(!(MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library",0)))
  877.     {
  878.         ShowError(ERR_NO_MATHTRANS,NULL,FALSE);
  879.  
  880.         return(FALSE);
  881.     }
  882.  
  883.     if(UseGUI)
  884.     {
  885.         if(!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  886.         {
  887.             ShowError(ERR_NO_MUI,NULL,FALSE);
  888.  
  889.             return(FALSE);
  890.         }
  891.     }
  892.  
  893.     DataTypesBase = OpenLibrary("datatypes.library",39);
  894.  
  895.     if(!(Pool = LibCreatePool(MEMF_ANY | MEMF_PUBLIC,8192,8192)))
  896.     {
  897.         ShowError(ERR_NO_POOL,NULL,FALSE);
  898.  
  899.         return(FALSE);
  900.     }
  901.  
  902.     Forbid();
  903.  
  904.     if(FindPort(SPECIAL_PORT))
  905.     {
  906.         ShowError(ERR_ALREADY_RUNNING,NULL,FALSE);
  907.  
  908.         Permit();
  909.  
  910.         return(FALSE);
  911.     }
  912.  
  913.     if(!(MainPort = CreateMsgPort()))
  914.     {
  915.         ShowError(ERR_NO_PORT,NULL,FALSE);
  916.  
  917.         Permit();
  918.  
  919.         return(FALSE);
  920.     }
  921.  
  922.     MainPort -> mp_Node . ln_Name = SPECIAL_PORT;
  923.  
  924.     AddPort(MainPort);
  925.  
  926.     Permit();
  927.  
  928.     if(GfxBase -> ChipRevBits0 & GFXF_BIG_BLITS)
  929.     {
  930.         WriteLine    = LargeWriteLine;
  931.         ReadLine    = LargeReadLine;
  932.     }
  933.     else
  934.     {
  935.         WriteLine    = SmallWriteLine;
  936.         ReadLine    = SmallReadLine;
  937.     }
  938.  
  939.     NewList(&MessageList);
  940.  
  941.     OldPtr = ThisProcess -> pr_WindowPtr;
  942.  
  943.     return(TRUE);
  944. }
  945.  
  946. VOID __stdargs
  947. PrintLine(STRPTR Format,...)
  948. {
  949.     if(ThisProcess)
  950.     {
  951.         STATIC UBYTE __far    LineBuffer[512];
  952.         va_list            VarArgs;
  953.  
  954.         va_start(VarArgs,Format);
  955.  
  956.         vsprintf(LineBuffer,Format,VarArgs);
  957.  
  958.         if(AP_Application)
  959.         {
  960.             struct ListEntry *Entry;
  961.  
  962.             if(Entry = (struct ListEntry *)AllocVecPooled(sizeof(struct ListEntry) + strlen(LineBuffer) + 1,MEMF_ANY))
  963.             {
  964.                 Entry -> Title = (STRPTR)(Entry + 1);
  965.  
  966.                 strcpy(Entry -> Title,LineBuffer);
  967.  
  968.                 AddTail(&MessageList,(struct Node *)Entry);
  969.  
  970.                 DoMethod(LV_Messages,MUIM_List_Insert,&Entry -> Title,1,MUIV_List_Insert_Bottom);
  971.  
  972.                 set(LV_Messages,MUIA_List_Active,MUIV_List_Active_Bottom);
  973.             }
  974.         }
  975.         else
  976.         {
  977.             if(ThisProcess -> pr_CLI)
  978.             {
  979.                 STRPTR    From    = LineBuffer,
  980.                     To    = LineBuffer;
  981.                 LONG    i;
  982.  
  983.                 for(i = 0 ; i < strlen(LineBuffer) ; i++)
  984.                 {
  985.                     if(LineBuffer[i] == '\33')
  986.                         To += 2;
  987.                     else
  988.                         *From++ = *To++;
  989.                 }
  990.  
  991.                 *To = 0;
  992.  
  993.                 FPrintf(ThisProcess -> pr_COS,"%s\n",LineBuffer);
  994.             }
  995.         }
  996.  
  997.         va_end(VarArgs);
  998.     }
  999. }
  1000.  
  1001. VOID __regargs
  1002. GetNewSize(struct special_map *SpecialMap,struct parse_result *Result,LONG *NewWidth,LONG *NewHeight,LONG DPI_X,LONG DPI_Y)
  1003. {
  1004.     *NewWidth    = (SpecialMap -> width    * Result -> hres * 10 + 5) / (DPI_X * 10);
  1005.     *NewHeight    = (SpecialMap -> height    * Result -> vres * 10 + 5) / (DPI_Y * 10);
  1006.  
  1007.     if(Result -> hsize != 0.0)
  1008.         *NewWidth = (LONG)(Result -> hsize * (float)Result -> hres + 0.5);
  1009.  
  1010.     if(Result -> vsize != 0.0)
  1011.         *NewHeight = (LONG)(Result -> vsize * (float)Result -> vres + 0.5);
  1012.  
  1013.     if(Result -> scale > 0.0)
  1014.     {
  1015.         *NewWidth = (LONG)(((float)(*NewWidth) * Result -> scale) + 0.5);
  1016.         *NewHeight = (LONG)(((float)(*NewHeight) * Result -> scale) + 0.5);
  1017.     }
  1018.     else
  1019.     {
  1020.         if(Result -> hscale > 0.0)
  1021.             *NewWidth = (LONG)(((float)(*NewWidth) * Result -> hscale) + 0.5);
  1022.  
  1023.         if(Result -> vscale > 0.0)
  1024.             *NewHeight = (LONG)(((float)(*NewHeight) * Result -> vscale) + 0.5);
  1025.     }
  1026. }
  1027.  
  1028. struct BitMap * __regargs
  1029. ProcessImage(struct special_msg *Message)
  1030. {
  1031.     STATIC struct special_map    SpecialMap;
  1032.     STATIC struct config_struct    ConfigBackup;
  1033.  
  1034.     UBYTE            LocalBuffer[256];
  1035.     struct parse_result    Result;
  1036.     struct BitMap        *BitMap = NULL;
  1037.     LONG            Width,Height,Sum1,Sum2,Error;
  1038.     STRPTR            String = Message -> special_string;
  1039.     BPTR            NewDir = NULL,OldDir = NULL,Home;
  1040.  
  1041.     if(Message -> msg . mn_Length >= 52 && TypeOfMem(BADDR(Message -> DVIdirLock)))
  1042.     {
  1043.         OldDir = CurrentDir(Message -> DVIdirLock);
  1044.  
  1045.         Home = Message -> DVIdirLock;
  1046.     }
  1047.     else
  1048.     {
  1049.         Home = (BPTR)~0;
  1050.  
  1051.         if(GetVar("TEXPICTPATH",LocalBuffer,256,NULL) > 0)
  1052.         {
  1053.             if(NewDir = Lock(LocalBuffer,ACCESS_READ))
  1054.             {
  1055.                 OldDir = CurrentDir(NewDir);
  1056.  
  1057.                 Home = NewDir;
  1058.             }
  1059.         }
  1060.     }
  1061.  
  1062.     PrintLine("Command string received (%d × %d DPI),",Message -> hresolution,Message -> vresolution);
  1063.     PrintLine("\"%s\"",Message -> special_string);
  1064.  
  1065.     memset(&Result,0,sizeof(struct parse_result));
  1066.     memset(&SpecialMap,0,sizeof(struct special_map));
  1067.     memcpy(&ConfigBackup,&Configuration,sizeof(struct config_struct));
  1068.  
  1069.     Result . hres        = Message -> hresolution;
  1070.     Result . vres        = Message -> vresolution;
  1071.     Result . mode        = BandW;
  1072.     Result . invert        = Configuration . invert_bmap;
  1073.     Result . base_dpi    = Configuration . base_dpi;
  1074.  
  1075.     strcpy(Result . psinit_file,"TeX:ps/init.ps");
  1076.  
  1077.     get(CY_Transfer,MUIA_Cycle_Active,&Result . transfer);
  1078.     get(CY_Render,MUIA_Cycle_Active,&Result . rendering);
  1079.  
  1080.     Sum2 = 0;
  1081.  
  1082.     Sum1 = DoCRC(String,strlen(String));
  1083.  
  1084.     if(!ParseSpecial(Message -> special_string,&Result))
  1085.     {
  1086.         Message -> ret = 5;
  1087.  
  1088.         PrintLine("Done.");
  1089.         PrintLine("");
  1090.  
  1091.         ShowProgress(0);
  1092.  
  1093.         if(OldDir)
  1094.             CurrentDir(OldDir);
  1095.  
  1096.         if(NewDir)
  1097.             UnLock(NewDir);
  1098.  
  1099.         return(NULL);
  1100.     }
  1101.  
  1102.     Configuration . invert_bmap    = Result . invert;
  1103.     Configuration . base_dpi    = Result . base_dpi;
  1104.  
  1105.     ChangeDrawMode(Result . transfer,Result . rendering,FALSE);
  1106.  
  1107.     SpecialMap . hoffset    = (LONG)(((float)Message -> hresolution * Result . hoffset) + 0.5);
  1108.     SpecialMap . voffset    = (LONG)(((float)Message -> vresolution * Result . voffset) + 0.5);
  1109.  
  1110.     Message -> ret    = 0;
  1111.     Message -> bmap    = &SpecialMap;
  1112.  
  1113.     SpecialMap . loc . map    = NULL;
  1114.     SpecialMap . where_is    = LOC_NONE;
  1115.  
  1116.     if(Result . iffile[0])
  1117.     {
  1118.         if(Configuration . draw_modus == DRAW_BORDER || Configuration . draw_modus == DRAW_RECT)
  1119.         {
  1120.             if(GetImageSize(Result . iffile,&Width,&Height,&Error))
  1121.             {
  1122.                 LONG NewWidth,NewHeight,DPI_X = Configuration . base_dpi,DPI_Y = Configuration . base_dpi;
  1123.  
  1124.                 SpecialMap . width    = Width;
  1125.                 SpecialMap . height    = Height;
  1126.  
  1127.                 if(Configuration . draw_modus == DRAW_BORDER)
  1128.                     SpecialMap . where_is = LOC_BORDER;
  1129.                 else
  1130.                     SpecialMap . where_is = LOC_RECTANGLE;
  1131.  
  1132.                 GetImageDPI(Result . iffile,&DPI_X,&DPI_Y,NULL);
  1133.  
  1134.                 GetNewSize(&SpecialMap,&Result,&NewWidth,&NewHeight,DPI_X,DPI_Y);
  1135.  
  1136.                 SpecialMap . width    = NewWidth;
  1137.                 SpecialMap . height    = NewHeight;
  1138.             }
  1139.             else
  1140.             {
  1141.                 STRPTR Result = ShowError(Error,NULL,TRUE);
  1142.  
  1143.                 if(Result)
  1144.                     PrintLine("\33bCannot determine picture size: %s.\33n",Result);
  1145.                 else
  1146.                     PrintLine("\33bCannot determine picture size.\33n");
  1147.  
  1148.                 Message -> ret = 5;
  1149.             }
  1150.         }
  1151.         else
  1152.         {
  1153.             UBYTE             FileName[MAX_FILENAME_LEN];
  1154.             struct GreyImage    *Image;
  1155.             LONG             i;
  1156.  
  1157.             if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1158.             {
  1159.                 LONG    DateResult;
  1160.                 BPTR    File;
  1161.                 LONG    Error;
  1162.  
  1163.                 if(!BuildName(FileName,Home,Result . iffile,Result . hres,Result . vres,Sum1,&Error))
  1164.                 {
  1165.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1166.  
  1167.                     if(Result)
  1168.                         PrintLine("\33bCannot store converted image: %s.\33n",Result);
  1169.                     else
  1170.                         PrintLine("\33bCannot store converted image.\33n");
  1171.  
  1172.                     Message -> ret = 5;
  1173.  
  1174.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1175.  
  1176.                     if(OldDir)
  1177.                         CurrentDir(OldDir);
  1178.  
  1179.                     if(NewDir)
  1180.                         UnLock(NewDir);
  1181.  
  1182.                     return(NULL);
  1183.                 }
  1184.  
  1185.                 Sum2 = Sum1 + 1;
  1186.  
  1187.                 if(File = Open(FileName,MODE_OLDFILE))
  1188.                 {
  1189.                     LONG Magic[2];
  1190.  
  1191.                     if(Read(File,Magic,sizeof(Magic)))
  1192.                     {
  1193.                         if(Magic[0] == MAGIC_WORD)
  1194.                             Sum2 = Magic[1];
  1195.                     }
  1196.  
  1197.                     Close(File);
  1198.                 }
  1199.  
  1200.                 DateResult = FileDateCheck(Result . iffile,FileName,&Error);
  1201.  
  1202. /*                if(Error || DateResult < 0 || InvertChanged) */
  1203.                 if(Error || DateResult < 0)
  1204.                     Sum2 = Sum1 + 1;
  1205.  
  1206.                 if(Sum1 == Sum2)
  1207.                 {
  1208.                     STATIC UBYTE BitMapFileName[MAX_FILENAME_LEN];
  1209.  
  1210.                     if(Configuration . draw_modus == DRAW_FILE)
  1211.                         SpecialMap . where_is = LOC_FILE;
  1212.                     else
  1213.                         SpecialMap . where_is = LOC_FILE_BORDER;
  1214.  
  1215.                     strcpy(BitMapFileName,FileName);
  1216.  
  1217.                     SpecialMap . loc . filename = BitMapFileName;
  1218.  
  1219.                     PrintLine("Done.");
  1220.                     PrintLine("");
  1221.  
  1222.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1223.  
  1224.                     if(OldDir)
  1225.                         CurrentDir(OldDir);
  1226.  
  1227.                     if(NewDir)
  1228.                         UnLock(NewDir);
  1229.  
  1230.                     return(NULL);
  1231.                 }
  1232.             }
  1233.  
  1234.             InvertChanged = FALSE;
  1235.  
  1236.             for(i = 0 ; i < 256 ; i++)
  1237.                 Filter[i] = i;
  1238.  
  1239.             BrightnessFilter(Filter,Result . bright);
  1240.             ContrastFilter(Filter,Result . contrast);
  1241.             GammaFilter(Filter,Result . gamma);
  1242.  
  1243.             if(Result . red < 1 && Result . green < 1 && Result . blue < 1)
  1244.             {
  1245.                 LONG R,G,B,Delta1,Delta2;
  1246.  
  1247.                 for(i = 0 ; i < 256 ; i++)
  1248.                 {
  1249.                     R = (i * 65536 * 299) / 1000;
  1250.                     G = (i * 65536 * 587) / 1000;
  1251.                     B = (i * 65536 * 114) / 1000;
  1252.  
  1253.                     Delta1 = i * 65536 - (R + G + B);
  1254.                     Delta2 = Delta1 / 2;
  1255.  
  1256.                     LumR[i] = R + Delta2;
  1257.                     LumG[i] = G + Delta1 - 2 * Delta2;
  1258.                     LumB[i] = B + Delta2;
  1259.                 }
  1260.             }
  1261.             else
  1262.             {
  1263.                 LONG R,G,B;
  1264.  
  1265.                 R = Result . red;
  1266.                 G = Result . green;
  1267.                 B = Result . blue;
  1268.  
  1269.                 while(R + G + B > 100)
  1270.                 {
  1271.                     if(G > 33 && R + G + B > 100)
  1272.                         G--;
  1273.  
  1274.                     if(R > 33 && R + G + B > 100)
  1275.                         R--;
  1276.  
  1277.                     if(B > 33 && R + G + B > 100)
  1278.                         B--;
  1279.                 }
  1280.  
  1281.                 for(i = 0 ; i < 256 ; i++)
  1282.                 {
  1283.                     LumR[i] = ((i * 65536) * R) / 100;
  1284.                     LumG[i] = ((i * 65536) * G) / 100;
  1285.                     LumB[i] = ((i * 65536) * B) / 100;
  1286.                 }
  1287.             }
  1288.  
  1289.             PrintLine("Loading picture from \"%s\"...",Result . iffile);
  1290.  
  1291.             if(Image = ReadImage(Result . iffile,Result . patch_colours,&Error))
  1292.             {
  1293.                 LONG NewWidth,NewHeight,DPI_X = Configuration . base_dpi,DPI_Y = Configuration . base_dpi;
  1294.  
  1295.                 Error = 0;
  1296.  
  1297.                 SpecialMap . width    = Image -> Width;
  1298.                 SpecialMap . height    = Image -> Height;
  1299.  
  1300.                 GetImageDPI(Result . iffile,&DPI_X,&DPI_Y,NULL);
  1301.  
  1302.                 GetNewSize(&SpecialMap,&Result,&NewWidth,&NewHeight,DPI_X,DPI_Y);
  1303.  
  1304.                 if(NewWidth > 32768 || NewHeight > 32768)
  1305.                     Error = ERR_TOO_LARGE;
  1306.                 else
  1307.                 {
  1308.                     PrintLine("Processing picture (size %d × %d)...",NewWidth,NewHeight);
  1309.  
  1310.                     SetMaxProgress(NewHeight - 1);
  1311.  
  1312.                     switch(Result . mode)
  1313.                     {
  1314.                         case BandW:
  1315.  
  1316.                             Error = ScaleImage(&BitMap,Image,NewWidth,NewHeight);
  1317.                             break;
  1318.  
  1319.                         case FS:
  1320.  
  1321.                             Error = DitherImage_FS(&BitMap,Image,NewWidth,NewHeight);
  1322.                             break;
  1323.  
  1324.                         case Burkes:
  1325.  
  1326.                             Error = DitherImage_Burkes(&BitMap,Image,NewWidth,NewHeight);
  1327.                             break;
  1328.  
  1329.                         case Sierra:
  1330.  
  1331.                             Error = DitherImage_Sierra(&BitMap,Image,NewWidth,NewHeight);
  1332.                             break;
  1333.  
  1334.                         case JJN:
  1335.  
  1336.                             Error = DitherImage_JJN(&BitMap,Image,NewWidth,NewHeight);
  1337.                             break;
  1338.  
  1339.                         case StevensonArce:
  1340.  
  1341.                             Error = DitherImage_Stevenson_Arce(&BitMap,Image,NewWidth,NewHeight);
  1342.                             break;
  1343.  
  1344.                         case Stucki:
  1345.  
  1346.                             Error = DitherImage_Stucki(&BitMap,Image,NewWidth,NewHeight);
  1347.                             break;
  1348.  
  1349.                         case BlueNoise:
  1350.  
  1351.                             Error = DitherImage_BlueNoise(&BitMap,Image,NewWidth,NewHeight,Result . threshold);
  1352.                             break;
  1353.  
  1354.                         case Ordered:
  1355.  
  1356.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedVanilla);
  1357.                             break;
  1358.  
  1359.                         case Halftone:
  1360.  
  1361.                             switch(Result . dither_opt)
  1362.                             {
  1363.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone4);
  1364.                                     break;
  1365.  
  1366.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone8);
  1367.                                     break;
  1368.  
  1369.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone);
  1370.                                     break;
  1371.                             }
  1372.  
  1373.                             break;
  1374.  
  1375.                         case RandomNoise:
  1376.  
  1377.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,NULL);
  1378.                             break;
  1379.  
  1380.                         case BckBrick:
  1381.  
  1382.                             switch(Result . dither_opt)
  1383.                             {
  1384.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick4);
  1385.                                     break;
  1386.  
  1387.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick8);
  1388.                                     break;
  1389.  
  1390.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick);
  1391.                                     break;
  1392.                             }
  1393.  
  1394.                             break;
  1395.  
  1396.                         case FwdBrick:
  1397.  
  1398.                             switch(Result . dither_opt)
  1399.                             {
  1400.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick4);
  1401.                                     break;
  1402.  
  1403.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick8);
  1404.                                     break;
  1405.  
  1406.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick);
  1407.                                     break;
  1408.                             }
  1409.  
  1410.                             break;
  1411.  
  1412.                         case Hexagon:
  1413.  
  1414.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHexagonalCluster);
  1415.                             break;
  1416.  
  1417.                         case SpiralDot:
  1418.  
  1419.                             switch(Result . dither_opt)
  1420.                             {
  1421.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot4);
  1422.                                     break;
  1423.  
  1424.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot8);
  1425.                                     break;
  1426.  
  1427.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot);
  1428.                                     break;
  1429.                             }
  1430.  
  1431.                             break;
  1432.  
  1433.                         case Horizontal:
  1434.  
  1435.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHorizontal);
  1436.                             break;
  1437.                     }
  1438.  
  1439.                     if(!BitMap)
  1440.                         Error = ERR_NO_MEM;
  1441.                 }
  1442.  
  1443.                 if(BitMap)
  1444.                 {
  1445.                     if(Configuration . draw_modus == DRAW_IN_MEM_B || Configuration . draw_modus == DRAW_FILE_B)
  1446.                         SpecialMap . where_is = LOC_BITMAP_BORDER;
  1447.                     else
  1448.                         SpecialMap . where_is = LOC_BITMAP;
  1449.  
  1450.                     SpecialMap . width    = NewWidth;
  1451.                     SpecialMap . height    = NewHeight;
  1452.                     SpecialMap . loc . map    = (ULONG *)BitMap -> Planes[0];
  1453.  
  1454.                     if(Configuration . invert_bmap)
  1455.                         BltBitMap(BitMap,0,0,BitMap,0,0,NewWidth,NewHeight,0x50,1,NULL);
  1456.  
  1457.                     if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1458.                     {
  1459.                         struct AsyncFile *File;
  1460.  
  1461.                         PrintLine("Saving picture...");
  1462.  
  1463.                         Error = 0;
  1464.  
  1465.                         if(File = OpenAsync(FileName,MODE_WRITE,2 * 16384))
  1466.                         {
  1467.                             ULONG Magic[4];
  1468.  
  1469.                             Magic[0] = MAGIC_WORD;
  1470.                             Magic[1] = Sum1;
  1471.                             Magic[2] = SpecialMap . width;
  1472.                             Magic[3] = SpecialMap . height;
  1473.  
  1474.                             if(WriteAsync(File,Magic,sizeof(Magic)) == sizeof(Magic))
  1475.                             {
  1476.                                 PLANEPTR    Plane = BitMap -> Planes[0];
  1477.                                 LONG        i;
  1478.  
  1479.                                 SetMaxProgress(BitMap -> Rows - 1);
  1480.  
  1481.                                 for(i = 0 ; i < BitMap -> Rows ; i++)
  1482.                                 {
  1483.                                     if(WriteAsync(File,Plane,BitMap -> BytesPerRow) != BitMap -> BytesPerRow)
  1484.                                     {
  1485.                                         Error = IoErr();
  1486.  
  1487.                                         break;
  1488.                                     }
  1489.                                     else
  1490.                                     {
  1491.                                         Plane += BitMap -> BytesPerRow;
  1492.  
  1493.                                         ShowProgress(i);
  1494.                                     }
  1495.                                 }
  1496.                             }
  1497.                             else
  1498.                                 Error = IoErr();
  1499.  
  1500.                             CloseAsync(File);
  1501.                         }
  1502.                         else
  1503.                             Error = IoErr();
  1504.  
  1505.                         if(Error)
  1506.                         {
  1507.                             STRPTR Result = ShowError(ERR_NO_MEM,NULL,TRUE);
  1508.  
  1509.                             if(Result)
  1510.                                 PrintLine("\33bError saving picture: %s.\33n",Result);
  1511.                             else
  1512.                                 PrintLine("\33bError saving picture.\33n");
  1513.  
  1514.                             DeleteFile(FileName);
  1515.                         }
  1516.                         else
  1517.                             AddProtection(FileName,FIBF_EXECUTE);
  1518.                     }
  1519.  
  1520.                 }
  1521.  
  1522.                 if(!BitMap)
  1523.                 {
  1524.                     if(Error)
  1525.                     {
  1526.                         STRPTR Result = ShowError(Error,NULL,TRUE);
  1527.  
  1528.                         if(Result)
  1529.                             PrintLine("\33b%s.\33n",Result);
  1530.                     }
  1531.  
  1532.                     Message -> ret = 5;
  1533.                 }
  1534.  
  1535.                 DeleteImage(Image);
  1536.             }
  1537.             else
  1538.             {
  1539.                 STRPTR Result = ShowError(Error,NULL,TRUE);
  1540.  
  1541.                 if(Result)
  1542.                     PrintLine("\33bError loading picture: %s.\33n",Result);
  1543.                 else
  1544.                     PrintLine("\33bError loading picture.\33n");
  1545.  
  1546.                 Message -> ret = 5;
  1547.             }
  1548.         }
  1549.     }
  1550.  
  1551.     if(Result . psfile[0])
  1552.     {
  1553.         PSGetSizeDot(&Result, &(SpecialMap . width), &(SpecialMap . height), &(SpecialMap . hoffset), &(SpecialMap . voffset));
  1554.         SpecialMap . voffset = - SpecialMap . voffset;
  1555.  
  1556.         if(Configuration . draw_modus == DRAW_BORDER || Configuration . draw_modus == DRAW_RECT)
  1557.         {
  1558.             if(Configuration . draw_modus == DRAW_BORDER)
  1559.                 SpecialMap . where_is = LOC_BORDER;
  1560.             else
  1561.                 SpecialMap . where_is = LOC_RECTANGLE;
  1562.  
  1563. /*            PSGetSizeDot(&Result, &(SpecialMap . width), &(SpecialMap . height), &(SpecialMap . hoffset), &(SpecialMap . voffset));
  1564.             SpecialMap . voffset = - SpecialMap . voffset;
  1565. */
  1566. /*
  1567.             if((Result . gotcontrol & SUFFICIENT_PS_ARGS) == SUFFICIENT_PS_ARGS)
  1568.             {
  1569.                 LONG    OldWidth    = Result . urx - Result . llx,
  1570.                     OldHeight    = Result . ury - Result . lly;
  1571.  
  1572.                 if(Result . gotcontrol & GOT_RHI)
  1573.                 {
  1574.                     SpecialMap . width    = (Result . hres * Result . rwi) / 720;
  1575.                     SpecialMap . height    = (Result . vres * Result . rhi) / 720;
  1576.                 }
  1577.                 else
  1578.                 {
  1579.                     SpecialMap . width    = (Result . hres * Result . rwi) / 720;
  1580.                     SpecialMap . height    = (Result . vres * OldHeight * Result . rwi) / (720 * OldWidth);
  1581.                 }
  1582.             }
  1583.             else
  1584.             {
  1585.                 SpecialMap . width    = (LONG)(Result . hsize * (float)Result . hres + 0.5),
  1586.                 SpecialMap . height    = (LONG)(Result . vsize * (float)Result . vres + 0.5);
  1587.             }
  1588.  
  1589.             if(Result . scale > 0.0)
  1590.             {
  1591.                 SpecialMap . width = (LONG)(((float)SpecialMap . width * Result . scale) + 0.5);
  1592.                 SpecialMap . height = (LONG)(((float)SpecialMap . height * Result . scale) + 0.5);
  1593.             }
  1594.             else
  1595.             {
  1596.                 if(Result . hscale > 0.0)
  1597.                     SpecialMap . width = (LONG)(((float)SpecialMap . width * Result . hscale) + 0.5);
  1598.  
  1599.                 if(Result . vscale > 0.0)
  1600.                     SpecialMap . height = (LONG)(((float)SpecialMap . height * Result . vscale) + 0.5);
  1601.             }
  1602.  
  1603. */
  1604.         }
  1605.         else
  1606.         {
  1607.             UBYTE FileName[MAX_FILENAME_LEN];
  1608.  
  1609.             if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1610.             {
  1611.                 LONG    DateResult;
  1612.                 BPTR    File;
  1613.                 LONG    Error;
  1614.  
  1615.                 if(!BuildName(FileName,Home,Result . psfile,Result . hres,Result . vres,Sum1,&Error))
  1616.                 {
  1617.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1618.  
  1619.                     if(Result)
  1620.                         PrintLine("\33bCannot store converted image: %s.\33n",Result);
  1621.                     else
  1622.                         PrintLine("\33bCannot store converted image.\33n");
  1623.  
  1624.                     Message -> ret = 5;
  1625.  
  1626.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1627.  
  1628.                     if(OldDir)
  1629.                         CurrentDir(OldDir);
  1630.  
  1631.                     if(NewDir)
  1632.                         UnLock(NewDir);
  1633.  
  1634.                     return(NULL);
  1635.                 }
  1636.  
  1637.                 Sum2 = Sum1 + 1;
  1638.  
  1639.                 if(File = Open(FileName,MODE_OLDFILE))
  1640.                 {
  1641.                     LONG Magic[2];
  1642.  
  1643.                     if(Read(File,Magic,sizeof(Magic)))
  1644.                     {
  1645.                         if(Magic[0] == MAGIC_WORD)
  1646.                             Sum2 = Magic[1];
  1647.                     }
  1648.  
  1649.                     Close(File);
  1650.                 }
  1651.  
  1652.                 DateResult = FileDateCheck(Result . psfile,FileName,&Error);
  1653.  
  1654. /*                if(Error || DateResult < 0 || InvertChanged) */
  1655.                 if(Error || DateResult < 0)
  1656.                     Sum2 = Sum1 + 1;
  1657.  
  1658.                 if(Sum1 == Sum2)
  1659.                 {
  1660.                     STATIC UBYTE BitMapFileName[MAX_FILENAME_LEN];
  1661.  
  1662.                     if(Configuration . draw_modus == DRAW_FILE)
  1663.                         SpecialMap . where_is = LOC_FILE;
  1664.                     else
  1665.                         SpecialMap . where_is = LOC_FILE_BORDER;
  1666.  
  1667.                     strcpy(BitMapFileName,FileName);
  1668.  
  1669.                     SpecialMap . loc . filename = BitMapFileName;
  1670.  
  1671.                     PrintLine("Done.");
  1672.                     PrintLine("");
  1673.  
  1674.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1675.  
  1676.                     if(OldDir)
  1677.                         CurrentDir(OldDir);
  1678.  
  1679.                     if(NewDir)
  1680.                         UnLock(NewDir);
  1681.  
  1682.                     return(NULL);
  1683.                 }
  1684.             }
  1685.  
  1686.             InvertChanged = FALSE;
  1687.  
  1688.             if(BitMap = ProcessPostscript(Message,&SpecialMap,&Result,&Error))
  1689.             {
  1690.                 if(Configuration . draw_modus == DRAW_IN_MEM_B || Configuration . draw_modus == DRAW_FILE_B)
  1691.                     SpecialMap . where_is = LOC_BITMAP_BORDER;
  1692.                 else
  1693.                     SpecialMap . where_is = LOC_BITMAP;
  1694.  
  1695.                 SpecialMap . loc . map = (ULONG *)BitMap -> Planes[0];
  1696.  
  1697.                 if(Configuration . invert_bmap)
  1698.                     BltBitMap(BitMap,0,0,BitMap,0,0,SpecialMap . width,SpecialMap . height,0x50,1,NULL);
  1699.  
  1700.                 if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1701.                 {
  1702.                     struct AsyncFile *File;
  1703.  
  1704.                     PrintLine("Saving picture...");
  1705.  
  1706.                     Error = 0;
  1707.  
  1708.                     if(File = OpenAsync(FileName,MODE_WRITE,2 * 16384))
  1709.                     {
  1710.                         ULONG Magic[4];
  1711.  
  1712.                         Magic[0] = MAGIC_WORD;
  1713.                         Magic[1] = Sum1;
  1714.                         Magic[2] = SpecialMap . width;
  1715.                         Magic[3] = SpecialMap . height;
  1716.  
  1717.                         if(WriteAsync(File,Magic,sizeof(Magic)) == sizeof(Magic))
  1718.                         {
  1719.                             PLANEPTR    Plane = BitMap -> Planes[0];
  1720.                             LONG        i;
  1721.  
  1722.                             SetMaxProgress(BitMap -> Rows - 1);
  1723.  
  1724.                             for(i = 0 ; i < BitMap -> Rows ; i++)
  1725.                             {
  1726.                                 if(WriteAsync(File,Plane,BitMap -> BytesPerRow) != BitMap -> BytesPerRow)
  1727.                                 {
  1728.                                     Error = IoErr();
  1729.  
  1730.                                     break;
  1731.                                 }
  1732.                                 else
  1733.                                 {
  1734.                                     Plane += BitMap -> BytesPerRow;
  1735.  
  1736.                                     ShowProgress(i);
  1737.                                 }
  1738.                             }
  1739.                         }
  1740.                         else
  1741.                             Error = IoErr();
  1742.  
  1743.                         CloseAsync(File);
  1744.                     }
  1745.                     else
  1746.                         Error = IoErr();
  1747.  
  1748.                     if(Error)
  1749.                     {
  1750.                         STRPTR Result = ShowError(ERR_NO_MEM,NULL,TRUE);
  1751.  
  1752.                         if(Result)
  1753.                             PrintLine("\33bError saving picture: %s.\33n",Result);
  1754.                         else
  1755.                             PrintLine("\33bError saving picture.\33n");
  1756.  
  1757.                         DeleteFile(FileName);
  1758.                     }
  1759.                     else
  1760.                         AddProtection(FileName,FIBF_EXECUTE);
  1761.                 }
  1762.  
  1763.             }
  1764.             else
  1765.             {
  1766.                 if(Error)
  1767.                 {
  1768.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1769.  
  1770.                     if(Result)
  1771.                         PrintLine("\33b%s.\33n",Result);
  1772.                 }
  1773.  
  1774.                 Message -> ret = 5;
  1775.             }
  1776.         }
  1777.     }
  1778.  
  1779.     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1780.  
  1781.     PrintLine("Done.");
  1782.     PrintLine("");
  1783.  
  1784.     ShowProgress(0);
  1785.  
  1786.     if(OldDir)
  1787.         CurrentDir(OldDir);
  1788.  
  1789.     if(NewDir)
  1790.         UnLock(NewDir);
  1791.  
  1792.     return(BitMap);
  1793. }
  1794.  
  1795. VOID __saveds
  1796. HandleInput()
  1797. {
  1798.     if(OpenAll())
  1799.     {
  1800.         if(UseGUI)
  1801.         {
  1802.             if(OpenGUI())
  1803.             {
  1804.                 BOOL    Done = FALSE;
  1805.                 ULONG    SignalMask,Signals;
  1806.                 LONG    Value;
  1807.  
  1808.                 SignalMask = Signals = NULL;
  1809.  
  1810.                 do
  1811.                 {
  1812.                     if(Signals & SIGBREAKF_CTRL_C)
  1813.                         Done = TRUE;
  1814.  
  1815.                     switch(DoMethod(AP_Application,MUIM_Application_Input,&SignalMask))
  1816.                     {
  1817.                         case MEN_QUIT:
  1818.                         case MUIV_Application_ReturnID_Quit:
  1819.  
  1820.                             Done = TRUE;
  1821.                             break;
  1822.  
  1823.                         case GAD_TRANSFER:
  1824.  
  1825.                             ChangeDrawMode(0,0,TRUE);
  1826.                             break;
  1827.  
  1828.                         case GAD_RENDER:
  1829.  
  1830.                             ChangeDrawMode(0,0,TRUE);
  1831.                             break;
  1832.  
  1833.                         case GAD_INVERT:
  1834.  
  1835.                             get(CM_Invert,MUIA_Selected,&Value);
  1836.  
  1837.                             Configuration . invert_bmap = Value;
  1838.  
  1839.                             InvertChanged = TRUE;
  1840.  
  1841.                             break;
  1842.  
  1843.                         case GAD_BASEDPI:
  1844.  
  1845.                             get(ST_BaseDPI,MUIA_String_Integer,&Value);
  1846.  
  1847.                             if(!Value)
  1848.                                 set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  1849.                             else
  1850.                                 Configuration . base_dpi = Value;
  1851.  
  1852.                             break;
  1853.  
  1854.                         case GAD_JUMP:
  1855.  
  1856.                             Configuration . use_pubscr = TRUE;
  1857.  
  1858.                             SignalMask = NULL;
  1859.  
  1860.                             ThisProcess -> pr_WindowPtr = OldPtr;
  1861.  
  1862.                             MUI_DisposeObject(AP_Application);
  1863.  
  1864.                             AP_Application = NULL;
  1865.  
  1866.                             if(PubScreen)
  1867.                             {
  1868.                                 UnlockPubScreen(NULL,PubScreen);
  1869.  
  1870.                                 PubScreen = NULL;
  1871.                             }
  1872.  
  1873.                             if(!OpenGUI())
  1874.                             {
  1875.                                 ShowError(ERR_NO_GUI,NULL,FALSE);
  1876.  
  1877.                                 Done = TRUE;
  1878.                             }
  1879.                             else
  1880.                                 DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  1881.  
  1882.                             break;
  1883.  
  1884.                         case GAD_SHOW:
  1885.  
  1886.                             {
  1887.                                 struct Process *ShowDVI;
  1888.  
  1889.                                 Forbid();
  1890.  
  1891.                                 if(ShowDVI = (struct Process *)FindTask("ShowDVI-Task"))
  1892.                                 {
  1893.                                     Signal(ShowDVI,SIGBREAKF_CTRL_E);
  1894.  
  1895.                                     Permit();
  1896.                                 }
  1897.                                 else
  1898.                                 {
  1899.                                     Permit();
  1900.  
  1901.                                     PrintLine("ShowDVI is not currently running.");
  1902.                                 }
  1903.                             }
  1904.  
  1905.                             break;
  1906.  
  1907.                         case GAD_CLEAR:
  1908.  
  1909.                             DoMethod(LV_Messages,MUIM_List_Clear,0);
  1910.  
  1911.                             ClearList(&MessageList);
  1912.  
  1913.                             break;
  1914.  
  1915.                         case MEN_ABOUT:
  1916.  
  1917.                             MUI_Request(AP_Application,WI_Main,0,NULL,"Ok",
  1918.                                 "\33c\33\70"
  1919.                                 VERS
  1920.                                 "\33\62\n\n"
  1921.                                 "Last compiled "
  1922.                                 DATE
  1923.                                 "\n"
  1924.                                 "Copyright © 1993-1994 by Olaf `Olsen' Barthel & Georg Heßmann\n\n"
  1925.                                 "This is a MUI-Application.\n"
  1926.                                 "MUI is copyrighted by Stefan Stuntz.");
  1927.  
  1928.                             break;
  1929.  
  1930.                         case MEN_OPEN:
  1931.  
  1932.                             SetSleep(TRUE);
  1933.  
  1934.                             if(ReadConfig(&Configuration))
  1935.                             {
  1936.                                 SignalMask = NULL;
  1937.  
  1938.                                 ThisProcess -> pr_WindowPtr = OldPtr;
  1939.  
  1940.                                 MUI_DisposeObject(AP_Application);
  1941.  
  1942.                                 AP_Application = NULL;
  1943.  
  1944.                                 if(PubScreen)
  1945.                                 {
  1946.                                     UnlockPubScreen(NULL,PubScreen);
  1947.  
  1948.                                     PubScreen = NULL;
  1949.                                 }
  1950.  
  1951.                                 if(!OpenGUI())
  1952.                                 {
  1953.                                     ShowError(ERR_NO_GUI,NULL,FALSE);
  1954.  
  1955.                                     Done = TRUE;
  1956.                                 }
  1957.                                 else
  1958.                                     DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  1959.                             }
  1960.                             else
  1961.                             {
  1962.                                 SetSleep(FALSE);
  1963.  
  1964.                                 switch(Configuration . draw_modus)
  1965.                                 {
  1966.                                     case DRAW_IN_MEM:
  1967.  
  1968.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  1969.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  1970.                                         break;
  1971.  
  1972.                                     case DRAW_FILE:
  1973.  
  1974.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  1975.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  1976.                                         break;
  1977.  
  1978.                                     case DRAW_IN_MEM_B:
  1979.  
  1980.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  1981.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  1982.                                         break;
  1983.  
  1984.                                     case DRAW_FILE_B:
  1985.  
  1986.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  1987.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  1988.                                         break;
  1989.  
  1990.                                     case DRAW_BORDER:
  1991.  
  1992.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  1993.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  1994.                                         break;
  1995.  
  1996.                                     case DRAW_RECT:
  1997.  
  1998.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  1999.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Clear);
  2000.                                         break;
  2001.                                 }
  2002.  
  2003.                                 set(CM_Invert,MUIA_Selected,Configuration . invert_bmap);
  2004.  
  2005.                                 InvertChanged = TRUE;
  2006.  
  2007.                                 set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  2008.                             }
  2009.  
  2010.                             break;
  2011.  
  2012.                         case MEN_SAVE:
  2013.  
  2014.                             SetSleep(TRUE);
  2015.  
  2016.                             SaveConfig(&Configuration);
  2017.  
  2018.                             SetSleep(FALSE);
  2019.  
  2020.                             break;
  2021.  
  2022.                         case MEN_PUBSCREEN:
  2023.  
  2024.                             {
  2025.                                 struct Window    *Window;
  2026.                                 BOOL         Reopen = FALSE;
  2027.  
  2028.                                 if(get(WI_Main,MUIA_Window_Window,&Window))
  2029.                                 {
  2030.                                     if(Window)
  2031.                                     {
  2032.                                         struct MenuItem *Item;
  2033.  
  2034.                                         if(Item = ItemAddress(Window -> MenuStrip,FULLMENUNUM(0,3,NOSUB)))
  2035.                                         {
  2036.                                             if(Item -> Flags & CHECKED)
  2037.                                             {
  2038.                                                 if(!Configuration . use_pubscr)
  2039.                                                     Reopen = Configuration . use_pubscr = TRUE;
  2040.                                             }
  2041.                                             else
  2042.                                             {
  2043.                                                 if(Configuration . use_pubscr)
  2044.                                                 {
  2045.                                                     Reopen                = TRUE;
  2046.                                                     Configuration . use_pubscr    = FALSE;
  2047.                                                 }
  2048.                                             }
  2049.                                         }
  2050.                                     }
  2051.                                 }
  2052.  
  2053.                                 if(Reopen)
  2054.                                 {
  2055.                                     SignalMask = NULL;
  2056.  
  2057.                                     ThisProcess -> pr_WindowPtr = OldPtr;
  2058.  
  2059.                                     MUI_DisposeObject(AP_Application);
  2060.  
  2061.                                     AP_Application = NULL;
  2062.  
  2063.                                     if(PubScreen)
  2064.                                     {
  2065.                                         UnlockPubScreen(NULL,PubScreen);
  2066.  
  2067.                                         PubScreen = NULL;
  2068.                                     }
  2069.  
  2070.                                     if(!OpenGUI())
  2071.                                     {
  2072.                                         ShowError(ERR_NO_GUI,NULL,FALSE);
  2073.  
  2074.                                         Done = TRUE;
  2075.                                     }
  2076.                                     else
  2077.                                         DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  2078.                                 }
  2079.                             }
  2080.  
  2081.                             break;
  2082.                     }
  2083.  
  2084.                     if(!Done)
  2085.                     {
  2086.                         if(Signals & SIGBREAKF_CTRL_E)
  2087.                         {
  2088.                             Signals = NULL;
  2089.  
  2090.                             Configuration . use_pubscr = FALSE;
  2091.  
  2092.                             SignalMask = NULL;
  2093.  
  2094.                             ThisProcess -> pr_WindowPtr = OldPtr;
  2095.  
  2096.                             MUI_DisposeObject(AP_Application);
  2097.  
  2098.                             AP_Application = NULL;
  2099.  
  2100.                             if(PubScreen)
  2101.                             {
  2102.                                 UnlockPubScreen(NULL,PubScreen);
  2103.  
  2104.                                 PubScreen = NULL;
  2105.                             }
  2106.  
  2107.                             if(!OpenGUI())
  2108.                             {
  2109.                                 ShowError(ERR_NO_GUI,NULL,FALSE);
  2110.  
  2111.                                 Done = TRUE;
  2112.                             }
  2113.                             else
  2114.                                 DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  2115.                         }
  2116.  
  2117.                         if(Signals & PORTMASK(MainPort))
  2118.                         {
  2119.                             struct special_msg    *Message;
  2120.                             struct BitMap        *BitMap;
  2121.  
  2122.                             while(Message = (struct special_msg *)GetMsg(MainPort))
  2123.                             {
  2124.                                 switch(Message -> action)
  2125.                                 {
  2126.                                     case AC_SEND_SPECIAL:
  2127.  
  2128.                                         SetSleep(TRUE);
  2129.  
  2130.                                         BitMap = ProcessImage(Message);
  2131.  
  2132.                                         Message -> action = AC_REPLY_SPECIAL;
  2133.  
  2134.                                         ReplyMsg((struct Message *)Message);
  2135.  
  2136.                                         WaitPort(MainPort);
  2137.  
  2138.                                         Message = (struct special_msg *)GetMsg(MainPort);
  2139.  
  2140.                                         if(Message -> action != AC_OK_BITMAP)
  2141.                                             PrintLine("\33bExpected AC_OK_BITMAP but found %d!\33n",Message -> action);
  2142.  
  2143.                                         Message -> action    = AC_REPLY_BITMAP;
  2144.                                         Message -> ret        = 0;
  2145.  
  2146.                                         ReplyMsg((struct Message *)Message);
  2147.  
  2148.                                         if(BitMap)
  2149.                                             DeleteBitMap(BitMap);
  2150.  
  2151.                                         SetSleep(FALSE);
  2152.  
  2153.                                         break;
  2154.  
  2155.                                     case AC_SEND_TPIC:
  2156.  
  2157.                                         SetSleep(TRUE);
  2158.  
  2159.                                         work_with_tpic(Message -> tpic,Message -> dmap,Message -> hresolution,Message -> vresolution);
  2160.  
  2161.                                         Message -> action    = AC_REPLY_TPIC;
  2162.                                         Message -> ret        = 0;
  2163.  
  2164.                                         ReplyMsg((struct Message *)Message);
  2165.  
  2166.                                         SetSleep(FALSE);
  2167.  
  2168.                                         break;
  2169.  
  2170.                                     default:
  2171.  
  2172.                                         PrintLine("\33bUnknown action Nº%d.\33n",Message -> action);
  2173.  
  2174.                                         Message -> action    = AC_REPLY_UNKNOWN;
  2175.                                         Message -> ret        = 0;
  2176.  
  2177.                                         ReplyMsg((struct Message *)Message);
  2178.  
  2179.                                         break;
  2180.                                 }
  2181.                             }
  2182.                         }
  2183.  
  2184.                         if(!Done)
  2185.                         {
  2186.                             if(SignalMask)
  2187.                                 Signals = Wait(SignalMask | PORTMASK(MainPort) | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  2188.                             else
  2189.                                 Signals = CheckSignal(PORTMASK(MainPort) | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  2190.                         }
  2191.                     }
  2192.                 }
  2193.                 while(!Done);
  2194.  
  2195.                 ThisProcess -> pr_WindowPtr = OldPtr;
  2196.  
  2197.                 MUI_DisposeObject(AP_Application);
  2198.  
  2199.                 AP_Application = NULL;
  2200.  
  2201.                 if(PubScreen)
  2202.                 {
  2203.                     UnlockPubScreen(NULL,PubScreen);
  2204.  
  2205.                     PubScreen = NULL;
  2206.                 }
  2207.             }
  2208.             else
  2209.                 ShowError(ERR_NO_GUI,NULL,FALSE);
  2210.         }
  2211.         else
  2212.         {
  2213.             ULONG Signals;
  2214.  
  2215.             FOREVER
  2216.             {
  2217.                 Signals = Wait(PORTMASK(MainPort) | SIGBREAKF_CTRL_C);
  2218.  
  2219.                 if(Signals & SIGBREAKF_CTRL_C)
  2220.                     break;
  2221.                 else
  2222.                 {
  2223.                     if(Signals & PORTMASK(MainPort))
  2224.                     {
  2225.                         struct special_msg    *Message;
  2226.                         struct BitMap        *BitMap;
  2227.  
  2228.                         while(Message = (struct special_msg *)GetMsg(MainPort))
  2229.                         {
  2230.                             switch(Message -> action)
  2231.                             {
  2232.                                 case AC_SEND_SPECIAL:
  2233.  
  2234.                                     BitMap = ProcessImage(Message);
  2235.  
  2236.                                     Message -> action = AC_REPLY_SPECIAL;
  2237.  
  2238.                                     ReplyMsg((struct Message *)Message);
  2239.  
  2240.                                     WaitPort(MainPort);
  2241.  
  2242.                                     Message = (struct special_msg *)GetMsg(MainPort);
  2243.  
  2244.                                     if(Message -> action != AC_OK_BITMAP)
  2245.                                         PrintLine("\33bExpected AC_OK_BITMAP but found %d!\33n",Message -> action);
  2246.  
  2247.                                     Message -> action    = AC_REPLY_BITMAP;
  2248.                                     Message -> ret        = 0;
  2249.  
  2250.                                     ReplyMsg((struct Message *)Message);
  2251.  
  2252.                                     if(BitMap)
  2253.                                         DeleteBitMap(BitMap);
  2254.  
  2255.                                     break;
  2256.  
  2257.                                 case AC_SEND_TPIC:
  2258.  
  2259.                                     work_with_tpic(Message -> tpic,Message -> dmap,Message -> hresolution,Message -> vresolution);
  2260.  
  2261.                                     Message -> action    = AC_REPLY_TPIC;
  2262.                                     Message -> ret        = 0;
  2263.  
  2264.                                     ReplyMsg((struct Message *)Message);
  2265.  
  2266.                                     break;
  2267.  
  2268.                                 default:
  2269.  
  2270.                                     PrintLine("\33bUnknown action Nº%d.\33n",Message -> action);
  2271.  
  2272.                                     Message -> action    = AC_REPLY_UNKNOWN;
  2273.                                     Message -> ret        = 0;
  2274.  
  2275.                                     ReplyMsg((struct Message *)Message);
  2276.  
  2277.                                     break;
  2278.                             }
  2279.                         }
  2280.                     }
  2281.                 }
  2282.             }
  2283.         }
  2284.     }
  2285.  
  2286.     CloseAll();
  2287. }
  2288.  
  2289. #pragma libcall GfxBase WritePixelLine8 306 9A210806
  2290. #pragma libcall GfxBase ReadPixelLine8 300 9a210806
  2291.  
  2292. VOID __regargs
  2293. SmallWriteLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2294. {
  2295.     if(Width > 1008)
  2296.     {
  2297.         LONG    Size    = 1008,
  2298.             Offset    = 0;
  2299.  
  2300.         do
  2301.         {
  2302.             WritePixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2303.  
  2304.             Buffer    += Size;
  2305.             Offset    += Size;
  2306.             Width    -= Size;
  2307.  
  2308.             if(Width > 1008)
  2309.                 Size = 1008;
  2310.             else
  2311.                 Size = Width;
  2312.         }
  2313.         while(Width);
  2314.     }
  2315.     else
  2316.         WritePixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2317. }
  2318.  
  2319. VOID __regargs
  2320. SmallReadLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2321. {
  2322.     if(Width > 1008)
  2323.     {
  2324.         LONG    Size    = 1008,
  2325.             Offset    = 0;
  2326.  
  2327.         do
  2328.         {
  2329.             ReadPixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2330.  
  2331.             Buffer    += Size;
  2332.             Offset    += Size;
  2333.             Width    -= Size;
  2334.  
  2335.             if(Width > 1008)
  2336.                 Size = 1008;
  2337.             else
  2338.                 Size = Width;
  2339.         }
  2340.         while(Width);
  2341.     }
  2342.     else
  2343.         ReadPixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2344. }
  2345.  
  2346. VOID __regargs
  2347. LargeWriteLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2348. {
  2349.     if(Width > 32752)
  2350.     {
  2351.         LONG    Size    = 32752,
  2352.             Offset    = 0;
  2353.  
  2354.         do
  2355.         {
  2356.             WritePixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2357.  
  2358.             Buffer    += Size;
  2359.             Offset    += Size;
  2360.             Width    -= Size;
  2361.  
  2362.             if(Width > 32752)
  2363.                 Size = 32752;
  2364.             else
  2365.                 Size = Width;
  2366.         }
  2367.         while(Width);
  2368.     }
  2369.     else
  2370.         WritePixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2371. }
  2372.  
  2373. VOID __regargs
  2374. LargeReadLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2375. {
  2376.     if(Width > 32752)
  2377.     {
  2378.         LONG    Size    = 32752,
  2379.             Offset    = 0;
  2380.  
  2381.         do
  2382.         {
  2383.             ReadPixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2384.  
  2385.             Buffer    += Size;
  2386.             Offset    += Size;
  2387.             Width    -= Size;
  2388.  
  2389.             if(Width > 32752)
  2390.                 Size = 32752;
  2391.             else
  2392.                 Size = Width;
  2393.         }
  2394.         while(Width);
  2395.     }
  2396.     else
  2397.         ReadPixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2398. }
  2399.